package com.example.rocketmq.batch;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

import java.util.ArrayList;
import java.util.List;

/**
 * 批量发送，每一批长度不能超过4M
 */
public class BatchProducer {
    public static void main(String[] args) throws Exception {
        DefaultMQProducer producer = new DefaultMQProducer("test_group");
        producer.setNamesrvAddr("192.168.228.101:9876;192.168.228.103:9876");
        producer.start();
        List<Message> messages = new ArrayList<>();
        messages.add(new Message("batch_topic", "*", "01 msg".getBytes()));
        messages.add(new Message("batch_topic", "*", "02 msg".getBytes()));
        messages.add(new Message("batch_topic", "*", "03 msg".getBytes()));
        messages.add(new Message("batch_topic", "*", "04 msg".getBytes()));
        messages.add(new Message("batch_topic", "*", "05 msg".getBytes()));
        messages.add(new Message("batch_topic", "*", "06 msg".getBytes()));
        messages.add(new Message("batch_topic", "*", "07 msg".getBytes()));
        messages.add(new Message("batch_topic", "*", "08 msg".getBytes()));
        
        SendResult result = producer.send(messages);
        System.out.println(result);
        producer.shutdown();
    }
}
